package 集合.元素搜索;

import java.util.ArrayList;
import java.util.Scanner;

public class 学生系统查询 {
    public static void main(String[] args) {
        ArrayList<Student> s=new ArrayList<>();
        s.add(new Student("2110305625","朱佳铖",18,"软件2109"));
        s.add(new Student("2110305626","李佳辉",18,"软件2107"));
        s.add(new Student("2110305627","杨杨",18,"软件2101"));
        s.add(new Student("2110305628","胡佳俊",18,"软件2103"));
        for (int i = 0; i < s.size(); i++) {
            Student S=s.get(i);
            System.out.println(S.getId()+"\t\t"+S.getName()+"\t\t"+S.getAge()+"\t\t"+S.getClassName());
        }
        Scanner sr=new Scanner(System.in);
        while(true){
            System.out.println("输入您要查询的id");
            String idsr=sr.next();
            Student S= chaxunid(s,idsr);
            if(S!=null){
                System.out.println("找到了该学生信息如下");
                System.out.println(S.getId()+"\t\t"+S.getName()+"\t\t"+S.getAge()+"\t\t"+S.getClassName());
            }else{
                System.out.println("查无此人");
            }
        }
    }
    public static Student chaxunid(ArrayList<Student> s,String id){
            for (int i = 0; i < s.size(); i++) {
                if(s.get(i).getId().equals(id)){
                    return s.get(i);
                }
            }
            return null;
    }
}

